home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-23 | 6.5 KB | 236 lines | [TEXT/GEOL] |
- Item 3920875 22-March-90 18:20PST
-
- From: D2652 Strategic Planning Sys, D Bell,PRT
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Off-Screen Bitmaps (long)
-
-
- TO: MacApp.Tech$
- FR: D2652, Dan Cooley, Strategic Planning Systems
- RE: MA Views and Off-screen Bitmaps
-
- Hello fellow MacAppers! I Have some comments and questions concerning the
- OSImage off-screen bitmapping package and MacApp views. I have been using
- OSImage for some time now in our last project for some simple off-screen
- drawing and on-screen scrolling. Our current project requires a bit more than
- that.
-
- The ideal goal is to somehow incorporate OSImage into the view heirarchy so
- that any number fo views and subviews in a window will do their thing and all
- get blasted back into the window.
-
- Well, I started thinking (and we all know how dangerous that is), and my first
- atempt was something like so. I created a subcall of TWindow and overrode the
- .DrawContents method to something like this:
-
- PROCEDURE TMyOldWindow.DrawContents; OVERRIDE;
- VAR
- aRect : Rect;
- savedPort : GrafPtr;
- hTheDevice : GDHandle;
- itsQDExtent : Rect;
- BEGIN
- HLock(Handle(SELF));
-
- GetGrafEnv(savedPort, hTheDevice);
-
- {$PUSH} {$H-}
- SetOSGrafEnv(fOSImage.fOsip, fOSImage.fDstRect, fOSImage.fOsip);
- {$POP}
-
- INHERITED DrawContents;
-
- SetGrafEnv(savedPort, hTheDevice);
-
- {$PUSH} {$H-}
- CopyBits(fOSImage.fOsip^.portbits, thePort^.portBits,
- fOSImage.fDstRect, fOSImage.fDstRect, srcCopy, NIL);
- {$POP}
-
- HUnlock(Handle(SELF));
- END;
-
-
- I thought, great!! How simple and elegent. But alas, this does not work
- because of the focusing methods needed in the MacApp view architecture. Every
- subview would focus and bomb the program because of a 'Port set incorrectly'
- error, or something or other. As far as I can tell, the only place to SAFELY
- use OSImage is within the .Draw methods of any view object type.
-
- My second attempt developed into a two part solution. I sublassed TWindow
- again and created the TOSImage object for it. Then all the subviews were
- modified to draw into the window's fOSImage object. Here is the code for my
- modified TWindow subclass:
-
-
- PROCEDURE TOSWindow.IRes(itsDocument: TDocument;
- itsSuperview: TView;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- anOSImage : TOSImage;
- someRect: Rect;
- wp : WindowPtr;
- BEGIN
- INHERITED IRes(itsDocument, itsSuperview, itsParams);
- fOSImage := NIL;
- { create the TOSImage object here }
- END;
-
-
-
-
- PROCEDURE TOSWindow.Update; OVERRIDE;
- VAR
- aRect : Rect;
- BEGIN
- IF Focus THEN BEGIN
- GetQDExtent(aRect);
- InvalidRect(aRect); { we do this for our needs, but not neccesary? }
-
- INHERITED Update;
- END;
-
- END;
-
-
-
- PROCEDURE TOSWindow.Draw(area: Rect); OVERRIDE;
- BEGIN
- { do nothing to avoid that fashing on every redraw }
- { TWindow.Draw performs an EraseRect call, but we don't want that }
- END;
-
-
-
- PROCEDURE TOSWindow.DrawContents; OVERRIDE;
- VAR
- aRect : Rect;
- savedPort : GrafPtr;
- hTheDevice : GDHandle;
- itsQDExtent : Rect;
- BEGIN
- HLock(Handle(SELF));
-
- GetGrafEnv(savedPort, hTheDevice); { set up to the offscreen bitmap }
-
- {$PUSH} {$H-}
- SetOSGrafEnv(fOSImage.fOsip, fOSImage.fDstRect, fOSImage.fOsip);
- {$POP}
-
- GetQDExtent(itsQDExtent); { We know its extent always fits in
- QuickDraw coordinates. }
- EraseRect(itsQDExtent); { clear the offscreen bitmap}
- { should we do this in .Draw??? }
-
- SetGrafEnv(savedPort, hTheDevice); {set it back to normal }
-
- INHERITED DrawContents;
-
- {$PUSH} {$H-}
- CopyBits(fOSImage.fOsip^.portbits, thePort^.portBits,
- fOSImage.fDstRect, fOSImage.fDstRect, srcCopy, NIL);
- {$POP}
-
- HUnlock(Handle(SELF));
- END;
-
-
-
- PROCEDURE TOSWindow.Resize(width, height: VCoordinate;
- invalidate: BOOLEAN); OVERRIDE;
- VAR
- aRect : Rect;
- didIt : BOOLEAN;
- BEGIN
- INHERITED Resize(width, height, invalidate);
-
- IF (fOSImage <> NIL) & Focus THEN BEGIN
- GetQDExtent(aRect);
- didIt := fOSImage.Adjust(aRect);
- END;
- END;
-
-
-
- PROCEDURE TOSWindow.Free; OVERRIDE;
- BEGIN
- FreeObject(fOSImage);
- INHERITED Free;
- END;
-
-
-
-
- Here is a sample of the code I use to draw in the OffScreen bitmap:
-
-
- PROCEDURE TMyView.Draw(area: Rect); OVERRIDE;
- VAR
- itsQDExtent : Rect;
- aString : Str255;
- savedPort : GrafPtr;
- hTheDevice : GDHandle;
- anOSImage : TOSImage;
- aRect : Rect;
-
- BEGIN
- HLock(Handle(SELF));
-
- GetGrafEnv(savedPort, hTheDevice); { save the current grafport stuff }
-
- anOSImage := TOSWindow(GetWindow).fOSImage;
- {$PUSH} {$H-}
- SetOSGrafEnv(anOSImage.fOsip, anOSImage.fDstRect, anOSImage.fOsip);
- {$POP} { switch the WINDOW's OSImage object }
-
- PenNormal;
- PenMode(srcOr); { for layers, we want to see thru everything }
-
- {Set font and size for subsequent display in the window}
- TextFont(ApplFont);
- TextSize(72);
-
- MoveTo(50, 50);
- DrawString('Hello');{ Draw the word 'Hello' in large type. }
-
- SetGrafEnv(savedPort, hTheDevice);
-
- HUnlock(Handle(SELF));
- END;
-
-
- For our current needs this is fine. But it has several blatant faults to it.
- First, all subviews draw relative to the windows OSImage bounds, that is they
- all draw relative to the upper left corner of the window. Second, all subviews
- of a subview do the same. Essentially, it removes MacApp's nifty view
- architecture.
-
- So my first question is, how do I maintain a subview's local corrdinates and
- it's relative position to it's superview while using OSImage. How do I
- maintain all of MacApp views properties while still drawing off-screen. Do I
- need to create an off-screen bitmap for each subview, or can I draw into one
- like I do above?
-
- Second, would this kind of thing be something to consider for some future
- version of the Guerrilla MacApp, like the scalable views. Maybe a flag in the
- TView object like .fDrawOffScreen that would be set in a superview and equal in
- a subviews. If that flag was TRUE then it would create its own OSImage
- object, and draw into that, plus all of its subviews too.
-
- My personal opinion is that off-screen bitmaps are something almost every
- Macintosh programmer eventually tackles. It would be nice if it were cleanly
- integrated into MacApp. Chalk another mark on the wish list.
-
- It sounds like a lot of work to implement, but if the interest is high... well
- let's just see how high before I go on...
-
- I look forward to your feedback.
-
- Dan Cooley
- Strategic Planning Systems
- ALink: D2652
-
-